﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WpfApp7.Command;

namespace WpfApp7.ViewModels
{
    public class MyCommandViewModel:ObservableObject
    {
        private string _userName;

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; OnPropertyChanged(); }
        }

        private string _pwd;

        public string Pwd
        {
            get { return _pwd; }
            set { _pwd = value; OnPropertyChanged(); }
        }

        //声明一个登录命令
        public wpf7Command LoginCommand { get; set; }
        //带参数的命令（不推荐）
        public wpf7Command ParamCommand { get; set; }
        //如果是命令要传参数，推荐用泛型
        public PdyCommand<string> PdyCommand { get; set; }

        public MyCommandViewModel()
        {
            LoginCommand = new wpf7Command(() =>
            {
                //一定要用属性去判断
                if(UserName == "admin" && Pwd == "123")
                {
                    MessageBox.Show("登录成功");
                }
                else
                {
                    MessageBox.Show("登录失败,用户名或密码错误");
                }
            });

            PdyCommand = new PdyCommand<string>(p =>
            {
                MessageBox.Show(p.ToString());
            });
        }
    }
}
